{template 'header', $module}
{*<link rel="stylesheet" type="text/css" href="image/message.css"/>*}

<div class="main-block bd-gray" >
    <div class="hd fn-clear">
        <h2 class="fn-left">站内信</h2>
    </div>
<ul id="data-nav" class="main-nav mt10 fn-clear">
    <li id="status_0"><a href="{url('member/message')}?action=send&status=0">发送站内信</a></li>
    <li id="status_3"><a href="{url('member/message')}?action=inbox&status=3">收件箱</a></li>
    <li id="status_4"><a href="{url('member/message')}?action=recycle&status=4">回收站</a></li>
    <li id="status_7"><a href="{url('member/message')}?action=setting&status=7">信件设置</a></li>
</ul>

{if $action == 'send'}
<form method="post" action="message.php" id="dform" >
	<input type="hidden" name="action" value="{$action}"/>
	<input type="hidden" name="typeid" value="{$typeid}"/>

	<table class="data-form" >
		<tr>
			<th width="90"><span class="cred">*</span> 收件人：</th>
			<td class="tr f_gray">
                <input type="text" size="45" name="message[touser]"  datatype="*2-999" nullmsg="请填写收件人"  value="{$touser}"/>&nbsp;
				<br/>多个收件人请按空格键隔开 最多同时发送给{$MOD[maxtouser]}个收件人
			</td>
		</tr>
		<tr>
			<th width="90"><span class="cred">*</span> 标题：</th>
			<td class="tr"><input type="text" size="60" name="message[title]"  datatype="*2-999" nullmsg="请填写标题" errormsg="最少输入2个字符" value="{$title}"/> <span id="dtitle" class="cred"></span></td>
		</tr>
		<tr>
			<th width="90"><span class="cred">*</span> 内容：</th>
			<td class="tr">
				{Post::kindEditor('message[content]', $moduleid, $content, 'datatype="*5-99999" nullmsg="请填写内容" errormsg="内容最少5字"','675px')}
			</td>
		</tr>

		{if $need_captcha}
			<tr>
				<th width="90"><span class="cred">*</span> 验证码：</th>
				<td class="tr">{template 'captcha', 'chip'} <span id="dcaptcha" class="cred"></span></td>
			</tr>
		{/if}
		<tr>
			<th width="90"></th>
			<td class="tr" height="50">
				<input type="submit" name="submit" value="确定" class="fn-left btn mr20"/>
                <input type="reset" name="reset" value="重置" class="fn-left btn"/>
				{if $MG[message_limit]}
					&nbsp;&nbsp;&nbsp;今日可发 <span class="cred">{$MG[message_limit]}</span> 次
					&nbsp;&nbsp;&nbsp;当前已发 <span>{$limit_used}</span> 次
					&nbsp;&nbsp;&nbsp;还可以发 <span>{$limit_free}</span> 次
				{/if}
			</td>
		</tr>
	</table>
</form>
<script type="text/javascript">
	seajs.use(['$', 'vf', 'vf-css', 'easyui','easyui-css'], function($){
		$('#dform').Validform({
			beforeCheck:function(curform){
				lemon.editor.message_content_.sync();
			}
		});
	})
</script>
{php $action='add'}
{elseif $action == 'edit'}
<form method="post" action="message.php" id="dform" onsubmit="return check();">
	<input type="hidden" name="action" value="{$action}"/>
	<input type="hidden" name="itemid" value="{$itemid}"/>

	<table class="data-form mt10 c000 con layout-right ">

		<tr>
			<th width="90">*收件人：</th>
			<td class="tr f_gray"><input type="text" size="45" name="message[touser]"  datatype="*2-999" nullmsg="请填写收件人"  value="{$touser}"/> <a href="friend.php" class="t">[我的好友]</a> <span id="dtouser" class="cred"></span><br/>多个收件人请按空格键隔开 最多同时发送给{$MOD[maxtouser]}个收件人</td>
		</tr>
		<tr>
			<th width="90">*标题：</th>
			<td class="tr f_gray"><input type="text" size="60" name="message[title]"  datatype="*2-999" nullmsg="请填写标题"  value="{$title}"/> <span id="dtitle" class="cred"></span></td>
		</tr>
		<tr>
			<th width="90">* 内容：</th>
			<td class="tr">
				{Post::kindEditor('message[content]', $moduleid, $content, 'datatype="*5-99999" nullmsg="请填写内容" errormsg="内容最少5字"','675px')}
			</td>
		</tr>
		<tr>
			<th width="90">选项：</th>
			<td class="tr">
                <input class="nobd fn-left mr5" type="checkbox" name="message[send]" id="sendmsg" value="1" onclick="if(!this.checked){Dd('copy').checked=Dd('feedback').checked=false;}"/>
                <label for="sendmsg" class="fn-left mr10">已读回执发送信件</label>
                <input class="nobd fn-left mr5"  type="checkbox" name="message[copy]" id="copy" value="1" onclick="if(this.checked){Dd('save').checked=true;}"/>
                <label for="copy" class="fn-left mr10">保存到已发送</label>
                <input class="nobd fn-left mr5"  type="checkbox" name="message[feedback]" id="feedback" value="1" onclick="if(this.checked){Dd('save').checked=true;}"/>
                <label for="feedback" class="fn-left mr10">已读回执</label>
			</td>
		</tr>
		<tr>
			<th width="90">&nbsp;</th>
			<td class="tr" height="50">
                <input type="submit" name="submit" value="修改" class="fn-left btn mr20"/>
                <input type="button" value="返回" class="fn-left btn" onclick="history.back(-1);"/>
            </td>
		</tr>
	</table>
</form>
<script type="text/javascript">
	seajs.use(['$', 'vf', 'vf-css', 'easyui','easyui-css'], function($){
		$('#dform').Validform({
			beforeCheck:function(curform){
				lemon.editor.post_content_.sync();
			}
		});
	})
</script>
{php $action='draft'}
{elseif $action == 'export'}
<form method="post" action="message.php">
	<input type="hidden" name="action" value="{$action}"/>

	<table class="data-form mt10 c000 con layout-right ">
		<tr>
			<th width="90">提示：</th>
			<td class="tr f_blue">&nbsp;请定期导出重要信件，以免被系统自动清除</td>
		</tr>
		<tr>
			<th width="90">信件：</th>
			<td class="tr">
				<input id="inbox" class="nobd fn-left mr5" type="radio" value="3" name="message[status]" checked="checked"/>
                <label class="fn-left mr10" for="inbox">收件箱</label>
				<input id="sended" class="nobd fn-left mr5" type="radio" value="2" name="message[status]"/>
                <label class="fn-left mr10" for="sended">已发送</label>
				<input id="draft" class="nobd fn-left mr5" type="radio" value="1" name="message[status]"/>
                <label class="fn-left mr10" for="draft">草稿箱</label>
				<input id="del" class="nobd fn-left mr5" type="radio" value="4" name="message[status]"/>
                <label class="fn-left mr10" for="del">回收站</label>
			</td>
		</tr>
		<tr>
			<th width="90">日期范围：</th>
			<td class="tr">
				{Post::calender('message[fromdate]', $fromdate, 'width:100')} 至 {Post::calender('message[todate]', $todate, 'width:100', true)}
				<br/><span class="f_gray">每次最多导出100封，请设置合理的时间段，以免遗漏部分信件</span>
			</td>
		</tr>
		<tr>
			<th width="90">选项：</th>
			<td class="tr">
				<input id="exportUnread" class="nobd fn-left mr5" type="checkbox" value="1" name="message[isread]"/>
                <label for="exportUnread" class="fn-left mr10">仅导出未读信件</label>
			</td>
		</tr>
		<tr>
			<th width="90"></th>
			<td class="tr" height="50">
				<input type="submit" name="submit" value="导出" class=" fn-left btn mr20"/>
                <input type="reset" name="reset" value="重置" class="fn-left btn"/>
			</td>
		</tr>
	</table>
</form>
{elseif $action == 'empty'}
<form method="post" action="message.php">
	<input type="hidden" name="action" value="{$action}"/>

	<table class="data-form mt10 c000 con layout-right">

		<tr>
			<th width="90">信件：</th>
			<td class="tr">
                <input id="inbox" class="nobd fn-left mr5" type="radio" value="3" name="message[status]" checked="checked"/>
                <label class="fn-left mr10" for="inbox">收件箱</label>
                <input id="sended" class="nobd fn-left mr5" type="radio" value="2" name="message[status]"/>
                <label class="fn-left mr10" for="sended">已发送</label>
                <input id="draft" class="nobd fn-left mr5" type="radio" value="1" name="message[status]"/>
                <label class="fn-left mr10" for="draft">草稿箱</label>
                <input id="del" class="nobd fn-left mr5" type="radio" value="4" name="message[status]"/>
                <label class="fn-left mr10" for="del">回收站</label>
			</td>
		</tr>
		<tr>
			<th width="90">日期范围：</th>
			<td class="tr">
				{Post::calender('message[fromdate]', $fromdate, 'width:100')} 至 {Post::calender('message[todate]', $todate, 'width:100', true)}
			</td>
		</tr>
		<tr>
			<th width="90">选项：</th>
			<td class="tr">
				<input id="keepUnread" class="nobd fn-left mr5" type="checkbox" value="1" name="message[isread]" checked/>
                <label for="keepUnread" class="fn-left mr10">保留未读信件</label>
			</td>
		</tr>
		<tr>
			<th width="90"></th>
			<td class="tr" height="50">
				<input type="submit" name="submit" value="清理" class="fn-left btn mr20" onclick="if(!confirm('确定要清理吗？此操作将不可撤销')) return false;"/>
                <input type="reset" name="reset" value="重置" class="fn-left btn"/>
			</td>
		</tr>
	</table>
</form>
{elseif $action == 'show'}
    <div class="message-wrap">
        <div class="message-hd">
            <h2 class="f14">{$title}</h2>
            {if $status==4 || $status==3}
            {if $fromuser}
            <span>发件人：</span><a href="{userurl($fromuser)}" target="_blank" class="t">{$fromuser}</a><br/>
            {/if}
            {elseif $status==2}
            <span>收件人：</span><a href="{userurl($touser)}" target="_blank" class="t">{$touser}</a><br/>
            {/if}
            <span>编&nbsp;&nbsp;&nbsp;号：</span>{$itemid}<br/>
            <span>时&nbsp;&nbsp;&nbsp;间：</span>{$addtime}<br/>
        </div>
        <div class="message-content">
            {$content}
        </div>
        <div class="message-foot fn-clear">
            <input type="button" value="返回" class="btn fn-left mr5" onclick="history.back(-1);"/>
            {if $status==4}
            <input type="button" class="btn fn-left mr5" value="还原" onclick="window.location='?action=restore&itemid={$itemid}&forward={urlencode('?action=inbox')}';"/>
            {if $fromuser}
            <input type="button" class="btn fn-left mr5" value="回复" onclick="window.location='?action=send&touser={$fromuser}&title=RE:{urlencode($title)}';"/>
            <input type="button" class="btn fn-left mr5" value="转发" onclick="Dd('_send').submit();"/>
            <input type="button" class="btn fn-left mr5" value="拒收" onclick="if(confirm('确定要拒绝来自 {$fromuser} 的站内信吗？'))window.location='?action=refuse&username={$fromuser}';"/>
            {/if}
            <input type="button" class="btn fn-left mr5" value="彻底删除" onclick="if(confirm('确定要删除此信件吗？此操作不可撤销')) window.location='?action=delete&itemid={$itemid}&forward={urlencode('?action=recycle')}';"/>
            {php $action='recycle'}
            {elseif $status==3}
            {if $fromuser}
            <input type="button" class="btn fn-left mr5" value="回复" onclick="window.location='?action=send&touser={$fromuser}&title=RE:{urlencode($title)}';"/>
            <input type="button" class="btn fn-left mr5" value="转发" onclick="Dd('_send').submit();"/>
            <input type="button" class="btn fn-left mr5" value="拒收" onclick="if(confirm('确定要拒绝来自 {$fromuser} 的站内信吗？'))window.location='?action=refuse&username={$fromuser}';"/>
            {/if}
            <input type="button" class="btn" value="回收站" onclick="window.location='?action=delete&itemid={$itemid}&forward={urlencode('?action=inbox')}';"/>
            <input type="button" class="btn fn-left mr5" value="彻底删除" onclick="if(confirm('确定要删除此信件吗？此操作不可撤销')) window.location='?action=delete&recycle=0&itemid={$itemid}&forward={urlencode('?action=inbox')}';"/>
            {php $action='inbox'}
            {elseif $status==2}
            {if $fromuser}
            <input type="button" class="btn fn-left mr5" value="转发" onclick="Dd('_send').submit();"/>
            {/if}
            <input type="button" class="btn fn-left mr5" value="彻底删除" onclick="if(confirm('确定要删除此信件吗？此操作不可撤销')) window.location='?action=delete&itemid={$itemid}&forward={urlencode('?action=outbox')}';"/>
            {php $action='outbox'}
            {elseif $status==1}
            {if $fromuser}
            <input type="button" class="btn fn-left mr5" value="转发" onclick="Dd('_send').submit();"/>
            {/if}
            <input type="button" class="btn fn-left mr5" value="彻底删除" onclick="if(confirm('确定要删除此信件吗？此操作不可撤销')) window.location='?action=delete&itemid={$itemid}&forward={urlencode('?action=draft')}';"/>
            {php $action='draft'}
            {elseif $status==0}
            {php $action='inbox'}
            {/if}
            <form action="message.php" method="post" id="_send">
                <input type="hidden" name="action" value="send"/>
                <textarea name="title" class="fn-hide">{$title}</textarea>
                <textarea name="content" class="fn-hide">{$content}</textarea>
            </form>
        </div>
    </div>

	{if $messages}
    <table class="filter-tb mt10 c000 con layout-right">

        <tr>
            <th  width="50">类型</th>
            <th >&nbsp;标 题</th>
            <th  width="150">发件人</th>
            <th  width="170" align="center">时 间</th>
        </tr>
        {loop $messages $message}
            <tr align="center" onmouseover="this.className='on';" onmouseout="this.className='';">
                <td><a href="?action={$action}&typeid={$message[typeid]}"><img src="image/message_{$message[typeid]}.gif" width="16" height="16" title="{$NAME[$message[typeid]]}" alt=""/></a></td>
                <td align="left"><a href="{if $status==1}?action=edit&itemid={$message[itemid]}{else}?action=show&itemid={$message[itemid]}{/if}"{if $status>2 && $message[feedback]}onclick="if(confirm('该信件请求发送已读回执，是否发送？')){ window.location=this.href+'&feedback=1';return false;}"{/if} class="f_b"
                                    title="{$message[title]}">{$message[dtitle]}</a></td>
                <td align="center">{if $message[userurl]}<a href="{$message[userurl]}" target="_blank">{$message[user]}</a>{else}{$message[user]}{/if}</td>
                <td>{$message[adddate]}</td>
            </tr>
        {/loop}
    </table>
	{/if}
	{elseif $action == 'setting'}
<form method="post" action="message.php">
	<input type="hidden" name="action" value="{$action}"/>

	<table class="data-form mt10 c000 con layout-right">
		<tr>
			<th  width="80">黑名单：</td>
			<td class="tr f_gray"><textarea name="black" id="black" style="width:500px;height:100px;overflow:visible;">{$user[black]}</textarea><br/>[提示] 直接输入会员名即可将会员列入黑名单，多个会员名请用空格键隔开，禁止游客请填Guest</td>

		</tr>
		<tr style="display:{if !$could_send}none{/if};">
			<th width="90">未读信转发：</th>
			<td class="tr f_gray">
				<input id="trans" class="nobd fn-left mr5" type="radio" name="send" value="1" {if $user[send]}checked{/if}/>
                <label for="trans" class="fn-left mr10">开启</label>
				<input id="untrans" class="nobd fn-left mr5" type="radio" name="send" value="0" {if !$user[send]}checked{/if}/>
                <label for="untrans" class="fn-left mr10">关闭</label>
				系统将自动转发未读站内信至注册邮箱
			</td>
		</tr>
		<tr>
			<th width="90"></th>
			<td height="50" class="tr">
				<input type="submit" name="submit" value="更新" class="fn-left btn mr20"/>
                <input type="reset" name="reset" value="重置" class="fn-left btn"/>
			</td>
		</tr>
	</table>
</form>
	{else}

<div class="con">


<form id="pub-list" method="post">
    <table width='740' class="filter-tb mt10 c000">
        <tr>
            <th  width="20"><input class="nobd" type="checkbox" id="sel-all"/></th>
            <th  width="28">类型</th>
            <th width='200'>&nbsp;标 题</th>
            {if $status>1}
            <th  width="150">{if $status==2}收件人{else}发件人{/if}</th>{/if}
            <th  width="160" align="center">时 间</th>

            {if $status==3}
            <th width="50" align="center">标记</th>
            {/if}
        </tr>
        </thead>
        <tbody id="pub-list">
        {if $status==3}
            {loop $systems $message}
                <tr align="center" onmouseover="this.className='on';" onmouseout="this.className='';">
                    <td><input class="nobd" type="checkbox" disabled/></td>
                    <td><img src="image/message_sys.gif" width="16" height="16" title="系统广播" alt=""/></td>
                    <td align="left"><a href="?action=show&itemid={$message[itemid]}"><span class="cred" title="{$message[title]}">{$message[title]}</span></a></td>
                    <td>{$message[user]}</td>
                    <td>{$message[adddate]}</td>
                    {if $status==3}
                        <td>--</td>{/if}
                </tr>
            {/loop}
        {/if}
        {loop $messages $message}
            <tr align="center" onmouseover="this.className='on';" onmouseout="this.className='';">
                <td align="left"><input class="nobd" type="checkbox" name="itemid[]" value="{$message[itemid]}"/></td>
                <td align="left"><a href="?action={$action}&typeid={$message[typeid]}"><img src="image/message_{$message[typeid]}.gif" width="16" height="16" title="{$NAME[$message[typeid]]}" alt=""/></a></td>
                <td align="left"><a href="{if $status==1}?action=edit&itemid={$message[itemid]}{else}?action=show&itemid={$message[itemid]}{/if}"{if $status>2 && !$message[isread]} class="f_b"
                                    {if $message[feedback]}onclick="if(confirm('该信件请求发送已读回执，是否发送？')){ window.location=this.href+'&feedback=1';return false;}"{/if}{/if}{if $message[style]} style="color:#{$message[style]};"{/if} class="t"
                                    title="{$message[title]}&#10;编号：{$message[itemid]}">{$message[dtitle]}</a></td>
                {if $status>1}
                    <td align="left">{$message[touser]}</td>{/if}
                <td align="left">{$message[adddate]}</td>
                {if $status==3}
                    <td align="left">
                        <select name="style" onchange="window.location='?itemid={$message[itemid]}&action=color&style='+this.value;">
                            <option value="">标记</option>
                            <option value="">取消</option>
                            {$color_select}
                        </select>
                    </td>
                {/if}
            </tr>

        {/loop}
        </tbody>
    </table>
    <div class="mt10 fn-clear">
        {if $status==4}
        <input type="submit" value="还原" class="fn-left btn mr10" onclick="this.form.action='?action=restore';"/>
        <input type="submit" value="彻底删除" class="fn-left mr10 btn" onclick="if(confirm('确定要删除选中信件吗？此操作不可撤销')){this.form.action='?action=delete';}else{return false;}"/>
        {elseif $status==3}
        <span>
            <input class="fn-left mr10" type="text" value="输入编号,如135" size="15" id="m_id" onfocus="if(this.value=='输入编号,如135')this.value='';"/>
            <input type="button" value="查看" class="fn-left mr10 btn" onclick="if(Dd('m_id').value.match(/^[0-9]{1,}$/)){Go('?action=show&itemid='+Dd('m_id').value);return;}Dd('m_id').value='';Dd('m_id').focus();"/>
        </span>
        <input type="submit" value="标记已读" class="fn-left mr10 btn" onclick="this.form.action='?action=mark';"/>
        <input type="submit" value="回收站" class="fn-left mr10 btn" onclick="this.form.action='?action=delete';"/>
        <input type="submit" value="彻底删除" class="fn-left mr10 btn" onclick="if(confirm('确定要删除选中信件吗？此操作不可撤销')){this.form.action='?action=delete&recycle=0';}else{return false;}"/>
        {else}
        <input type="submit" value="彻底删除" class="fn-left mr10 btn" onclick="if(confirm('确定要删除选中信件吗？此操作不可撤销')){this.form.action='?action=delete';}else{return false;}"/>
        {/if}
        <input type="submit" value="清空" class="fn-left btn" onclick="if(confirm('确定要清空{$name}信件吗？此操作不可撤销')){this.form.action='?action=clear&status={$status}';}else{return false;}"/>
    </div>
</form>
</div>
	{if $status==3}
		{if $MG[inbox_limit]}
		<div class="con">收件箱容量 <span class="f_b cred">{$MG[inbox_limit]}</span> 条&nbsp;&nbsp;&nbsp;当前接收 <span class="f_b">{$limit_used}</span> 条&nbsp;&nbsp;&nbsp;还可以接收 <span class="f_b f_blue">{$limit_free}</span> 条&nbsp;&nbsp;&nbsp;建议定期删除无用信件</div>
		{/if}
	{/if}
<div class="con pages">{$pages}</div>
{/if}
<script type="text/javascript">
    seajs.use(['member'], function(member){
        member.active('menu_general', 'message', 'status_{$status}')
    })
    //s('message');m('{$action}');
</script>
</div>
{template 'footer',$module}